#include "bsp_callback.h"

extern osSemaphoreId_t uwb_transfer_handler;
extern uint8_t usart6_rcv_byte;  

CircularQueue_TypeDef usart6_queue = 
{
	.head = 0,
	.tail = 0
};
uint8_t uwb_rcv_res = 0;


void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	if(GPIO_Pin == GPIO_PIN_8)
	{
		/*UWB IRQ*/
		uint32_t mask;
		mask = dwt_read32bitreg(SYS_STATUS_ID) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR) ;
		if(mask & SYS_STATUS_RXFCG)
		{
			uwb_rcv_res=0;
		}
		else
		{
			uwb_rcv_res=1;
		}
		dwt_write32bitreg(SYS_STATUS_ID, mask);		
		osSemaphoreRelease(uwb_transfer_handler);		
	}
}



void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	if(huart->Instance == USART6)
	{
		usart6_queue.buf[usart6_queue.head++] = usart6_rcv_byte;
		usart6_queue.head &= QUEUE_BUF_MASK;
		/*enter to queue*/		
		HAL_UART_Receive_IT(huart,&usart6_rcv_byte,1);
	}


}
